package com.martin.study.mybatis.integrate.bean;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

//@Component
public class MineMapperFactoryBean implements FactoryBean {

	private Class mapperClass;

	public MineMapperFactoryBean(Class mapperClass) {
		this.mapperClass = mapperClass;
	}

	@Override
	public Object getObject() throws Exception {
		return Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{this.mapperClass}, new InvocationHandler() {
			@Override
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				System.out.println(method.getName());
				return null;
			}
		});
	}

	@Override
	public Class<?> getObjectType() {
		return this.mapperClass;
	}
}
